home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / adpcm / timing.c < prev   
C/C++ Source or Header  |  2000-05-18  |  1KB  |  52 lines

  1. /*
  2. ** Timing - Test timing on adpcm coder and decoder.
  3. **
  4. ** The program creates 10Kb garbage, and runs the compressor and
  5. ** the decompressor on it.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <math.h>
  10. #include "adpcm.h"
  11.  
  12. #define DATASIZE 10*1024    /* Data block size */
  13. #define DURATION 10        /* How many seconds to measure */
  14.  
  15. short pcmdata[DATASIZE];
  16. char adpcmdata[DATASIZE/2];
  17. short pcmdata_2[DATASIZE];
  18.  
  19. struct adpcm_state coder_1_state, coder_2_state, decoder_state;
  20.  
  21. main() {
  22.     int i;
  23.     int t0, t1, t2, t3;
  24.     int count = 0, count2;
  25.  
  26.     for(i=0; i<DATASIZE; i++)
  27.       pcmdata[i] = random() & 0xffff;
  28.  
  29.     t0 = time(0);
  30.     do {
  31.     adpcm_coder(pcmdata, adpcmdata, DATASIZE, &coder_1_state);
  32.     t1 = time(0);
  33.     count++;
  34.     } while (t1 < t0+DURATION);
  35.     printf("Coder: %d Ksample/second\n", count*DATASIZE/(1000*(t1-t0)));
  36.     printf("  (coded %d blocks of %d samples in %d seconds)\n",
  37.        count, DATASIZE, t1-t0);
  38.     t2 = time(0);
  39.     count2 = count;
  40.     while ( count2 > 0 ) {
  41.     adpcm_coder(pcmdata, adpcmdata, DATASIZE, &coder_2_state);
  42.     adpcm_decoder(adpcmdata, pcmdata_2, DATASIZE, &decoder_state);
  43.     count2--;
  44.     }
  45.     t3 = time(0);
  46.     printf("Decoder: %d Ksample/second\n",
  47.        count*DATASIZE/(1000*(t3-t2-t1+t0)));
  48.     printf("  (coded&decoded %d blocks of %d samples in %d seconds)\n",
  49.        count, DATASIZE, t3-t2);
  50.     exit(0);
  51. }
  52.